package com.classichu.jetpacksimple.data.local.converter;

import android.arch.persistence.room.TypeConverter;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

public class ListTypeConverter {
    @TypeConverter
    public static List<String> string2StringList(String json) {
        Gson gson = new Gson();
        Type listType = new TypeToken<ArrayList<String>>() {
        }.getType();
        return gson.fromJson(json, listType);
    }

    @TypeConverter
    public static String stringList2String(List<String> list) {
        Gson gson = new Gson();
        return gson.toJson(list);
    }

    @TypeConverter
    public static List<Integer> string2IntegerList(String json) {
        Gson gson = new Gson();
        Type listType = new TypeToken<ArrayList<String>>() {
        }.getType();
        return gson.fromJson(json, listType);
    }

    @TypeConverter
    public static String integerList2String(List<Integer> list) {
        Gson gson = new Gson();
        return gson.toJson(list);
    }
}

